<template>
  <div id="orderChange">
    <el-dialog
      title="修改订单信息"
      :visible.sync="centerDialogVisible"
      width="30%"
      center
    >
      <el-form ref="form" :model="types" label-width="80px" size="mini">
        <div class="input-box">
          <div class="admins-input">
            <el-form-item label="分类名称">
              <el-input v-model="types.typesName"></el-input>
            </el-form-item>
          </div>
        </div>
        <el-form-item size="large">
          <el-button type="primary" size="mini" @click="upload()"
            >修改</el-button
          >
          <el-button size="mini" @click="modalClose()">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapActions, mapState, mapMutations } = createNamespacedHelpers("Types");
export default {
  data() {
    return {
      centerDialogVisible: false,
      types: {
        typesName: "",
      },
    };
  },

  computed: {
    ...mapState(["typeById"]),
  },

  methods: {
    ...mapActions(["changeTypesById"]),
    async upload() {
      const data = await this.changeTypesById(this.types);
      switch (data.status) {
        case 1: {
          this.$message({
            duration: "1500",
            type: "success",
            message: "修改成功",
          });
          this.centerDialogVisible = false;
          break;
        }
        case 0: {
          this.$message({
            duration: "1500",
            type: "warning",
            message: "未改动",
          });
          break;
        }
        case 2: {
          this.$message({
            duration: "1500",
            type: "error",
            message: "修改失败,该账号已存在",
          });
          break;
        }
      }
    },

    init() {
      this.centerDialogVisible = true;
    },
    
    modalClose() {
      this.centerDialogVisible = false;
    },
  },
  watch: {
    typeById: {
      handler(value) {
        this.types = value;
      },
      deep: true,
    },
  },
};
</script>

<style lang="scss">
#orderChange {
  h3 {
    margin-bottom: 10px;
  }
  .addAdmin {
    width: 60%;
    margin: 0 auto;
    .el-form {
      padding: 30px 0;
      .el-input {
        width: 260px;
      }
    }
  }
}
</style>